<?php 
$v_filter = "";
if(isset($_REQUEST['hdn_filter'])){
	$v_filter=_replace_bad_char(trim($_REQUEST['hdn_filter']));
}	
$v_agency_id = 0;
if(isset($_REQUEST['hdn_agency_id'])){
	$v_agency_id = intval($_REQUEST['hdn_agency_id']);
}
if (!_check_permission_on_function($_SESSION['staff_id'], $_ISA_APP_CODE,_CONST_LIST_AGENCY_UPDATE)){?>
	<script>
		alert("<? echo _CONST_FUNCTION_PERMISSION_ERROR; ?>");
		window.history.back();	
	</script><?
	exit;
}
	SetDevEditPath($DEVEDIT_PATH);
	$short_des = new DevEdit();
	$short_des->SetName("txt_detail");
	$v_func = $short_des->GetValue(false);
	$v_url = "index.php?modal_dialog_mode=1" . "&hdn_agency_id=" . $v_agency_id . "&fuseaction=DISPLAY_SINGLE_AGENCY" ;
	$v_agency_id = intval($_REQUEST['hdn_agency_id']);
	$v_agency_function = $v_func;
	//$v_agency_function = $_REQUEST['txt_detail_html'];	
	$v_save_and_add_new = intval($_REQUEST['hdn_save_and_add_new']);
	$v_code = _restore_XML_bad_char(($_REQUEST['txt_code'])); 
	$v_name	= _restore_XML_bad_char(($_REQUEST['txt_name']));
	$v_address = _restore_XML_bad_char(($_REQUEST['txt_address']));
	$v_email	= _restore_XML_bad_char(($_REQUEST['txt_email']));
	$v_website = _restore_XML_bad_char(($_REQUEST['txt_website']));
	$v_mobile	= _restore_XML_bad_char(($_REQUEST['txt_mobile']));
	$v_tel = _restore_XML_bad_char(($_REQUEST['txt_tel']));
	$v_order = _restore_XML_bad_char(($_REQUEST['txt_order']));
	if ($v_order==""){$v_order = NULL;}
	$v_status = $_REQUEST['hdn_status'];

//Lay cac file anh dinh kem trong phan editor
/*for($m=0;$m<$MAX_COUNT_OF_IMAGE;$m++){ 
	$ten = "wBrowserFile_f".$m;
	if(isset($_FILES[$ten]['name'])){
			$c_image_editor_name = $_FILES[$ten]['name'];
			$c_image_editor_content = $_FILES[$ten]['tmp_name'];	
			$c_image_editor_size = $_FILES[$ten]['size'];
			if($c_image_editor_size > 0){
				$fp = fopen($c_image_editor_content,'rw');
				$c_image_editor_content = fread($fp, $c_image_editor_size);
				fclose($fp);
				$Image_EditorURL = $IMAGE_EDITOR_LOCATION.$c_image_editor_name;
				$fp=fopen($Image_EditorURL,"a+");
				if ($fp) {
					fwrite($fp,$c_image_editor_content);
					fclose($fp);
				}
				echo $Image_EditorURL;
			}
	 }
}
*/
if(_is_sqlserver()){
	$v_function_id = _save_text_to_database('T_TEMP_FILE', 'C_TEXT', $v_agency_function);
	$cmd = mssql_init("Onegate_AgencyUpdate",$conn);	
	mssql_bind($cmd,"@p_agency_id",$v_agency_id,SQLINT4);
	mssql_bind($cmd,"@p_code",$v_code,SQLVARCHAR);
	mssql_bind($cmd,"@p_name",$v_name,SQLVARCHAR);
	mssql_bind($cmd,"@p_address",$v_address,SQLVARCHAR);
	mssql_bind($cmd,"@p_email",$v_email,SQLVARCHAR);	
	mssql_bind($cmd,"@p_website",$v_website,SQLVARCHAR);	
	mssql_bind($cmd,"@p_mobile",$v_mobile,SQLVARCHAR);	
	mssql_bind($cmd,"@p_tel",$v_tel,SQLVARCHAR);	
	if (is_null($v_order)){
		mssql_bind($cmd,"@p_order",$v_order,SQLINT2, false, true, 2);
	}else{	
		mssql_bind($cmd,"@p_order",$v_order,SQLINT2);
	}	
	mssql_bind($cmd,"@p_status",$v_status,SQLINT1);
	mssql_bind($cmd,"@p_detail_func_id",$v_function_id,SQLVARCHAR);		
	$result = mssql_execute($cmd);
	$rs = @mssql_fetch_array($result);
	$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
	@mssql_free_result($result);
}
if (!is_null($v_error) and $v_error<>""){?>
	<script>
		alert("<?php echo $v_error; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<?php echo $v_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?php
	exit;
}?>
<form action="index.php" method="post" name="f_back">
	<input type="hidden" name="fuseaction" value="DISPLAY_ALL_AGENCY">
	<input name="hdn_filter" type="hidden" value="<?php echo $v_filter; ?>">
	<input name="hdn_agency_id" type="hidden" value="<?php echo $v_agency_id; ?>">
</form>
<Script language="javascript">
	if ("<?php echo $v_save_and_add_new; ?>" != "1")
		return_value = "<?php echo $v_agency_id; ?>" + _LIST_DELIMITOR + "<?php echo $v_code; ?>"  + _LIST_DELIMITOR + "<?php echo $v_name; ?>" + _LIST_DELIMITOR + "<?php echo $v_filter; ?>" 
	else
		return_value = "";
	goto_after_update_data(<?php echo $v_save_and_add_new; ?>, "DISPLAY_SINGLE_AGENCY",return_value);
</Script>
